package com.fang.db.dynamicdatasource02rwseparation.service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.fang.db.dynamicdatasource02rwseparation.contant.DBConstants;
import com.fang.db.dynamicdatasource02rwseparation.entity.OrderDO;
import com.fang.db.dynamicdatasource02rwseparation.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Description
 * @Author Bernie_fang
 * @Date 2022/12/18 22:52
 **/
@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Transactional
    @DS(DBConstants.DATASOURCE_MASTER)
    public void add(OrderDO order) {
        // 这里先假模假样的读取一下
        OrderDO orderDO = orderMapper.selectById(order.getId());
        System.out.println(orderDO);

        // 插入订单
        orderMapper.insert(order);

        System.out.println(10/0);
    }

    public OrderDO findById(Integer id) {
        return orderMapper.selectById(id);
    }

}